//
//  SinaStatusRetweetView.swift
//  SinaWeibo
//
//  Created by 王朝阳 on 2016/10/27.
//  Copyright © 2016年 wangzhaoyang. All rights reserved.
//

import UIKit

class SinaStatusRetweetView: UIView {
    
    // 记录约束
    var retweetViewCons: Constraint?
    
    //定义属性 共外界赋值
    var statusViewModel: SinaStatusViewModel?{
        didSet{
            //转发正文
            contentLabel.text = statusViewModel?.retweetContentText
            
            // 卸载约束
            retweetViewCons?.uninstall()
            // 有配图
            if (statusViewModel?.statusModel?.retweeted_status?.pic_urls?.count)! > 0 {
                pictureView.picUrls = statusViewModel?.statusModel?.retweeted_status?.pic_urls
                pictureView.isHidden = false
                
                self.snp_makeConstraints { (make) in
                    self.retweetViewCons = make.bottom.equalTo(pictureView).offset(10).constraint
                }
            }else {
                // 没有配图
                pictureView.isHidden = true
                self.snp_makeConstraints { (make) in
                    self.retweetViewCons = make.bottom.equalTo(contentLabel).offset(10).constraint
                }
            }

        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // MARK: - 设置视图
    private func setupUI(){
        backgroundColor = UIColor(white: 237/255, alpha: 1)
        // 01 添加控件
        addSubview(contentLabel)
        addSubview(pictureView)
        // 02 添加约束
        contentLabel.snp_makeConstraints { (make) in
            make.top.left.equalTo(10)
        }
        
        pictureView.snp_makeConstraints { (make) in
//            make.size.equalTo(CGSize(width:99, height: 100))
            make.left.equalTo(contentLabel)
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
        }
        
        self.snp_makeConstraints { (make) in
            self.retweetViewCons = make.bottom.equalTo(pictureView).offset(10).constraint
        }


    }
    // MARK: - 懒加载控件
    // 转发正文
    private lazy var contentLabel: UILabel = UILabel(text: "设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图", fontSize: SinaNormalFontSize, textColor: UIColor.darkGray, maxWidth: SinaScreenW - 20)

    //配图
    private lazy var pictureView: SinaStatusPictureView = {
        let view = SinaStatusPictureView()
        view.backgroundColor = self.backgroundColor
        return view
    }()
}
